package com.lhoverc.controller.user;

import com.lhoverc.annotation.Log;
import com.lhoverc.pojo.PageBean;
import com.lhoverc.pojo.Result;
import com.lhoverc.pojo.VO.ActivityVO;
import com.lhoverc.service.activity.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: LiCheng
 * @CreateTime: 2025-04-20
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("/user/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;


    /**
     * 获取最近的活动（仅限于申请中、报名中、活动中）
     *
     * @return
     */
    @GetMapping("/getRecentActivity")
    public Result getRecentActivity() {
        PageBean pageBean = activityService.getRecentActivity();
        return Result.success(pageBean);
    }

    /**
     * 获取历史活动信息
     */
    @GetMapping("/getActivityList")
    public Result getAllActivity(String activityName,
                                 Integer status,
                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime registrationDate,
                                 @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime activityDate) {
        List<ActivityVO> activityVOList = activityService.getActivityList(activityName, status, registrationDate, activityDate);
        return Result.success(activityVOList);
    }

    /**
     * 用户报名活动
     *
     * @param userId
     * @param activityId
     * @return
     */
    @Log
    @GetMapping("/addRegisterActivity/{userId}/{activityId}")
    public Result addRegisterActivity(@PathVariable Integer userId, @PathVariable Integer activityId) {
        activityService.addRegisterActivity(userId, activityId);
        return Result.success();
    }

    /**
     * 取消报名
     *
     * @param userId
     * @param activityId
     * @return
     */
    @Log
    @GetMapping("/deleteRegisterActivity/{userId}/{activityId}")
    public Result deleteRegisterActivity(@PathVariable Integer userId, @PathVariable Integer activityId) {
        activityService.deleteRegisterActivity(userId, activityId);
        return Result.success();
    }

    /**
     * 获取报名过的活动
     *
     * @param userId
     * @return
     */
    @GetMapping("/getRegisterActivities/{userId}")
    public Result getRegisterActivities(@PathVariable Integer userId) {
        List<Integer> registerIdList = activityService.getRegisterActivities(userId);
        return Result.success(registerIdList);
    }
}
